//
//  PhotoTestViewController.m
//  IceBreaker
//
//  Created by 老焦 on 12-10-13.
//  Copyright (c) 2012年 NDS. All rights reserved.
//

#import "PhotoTestViewController.h"

@interface PhotoTestViewController ()

@end

@implementation PhotoTestViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    [[UIApplication sharedApplication] setStatusBarHidden: YES withAnimation: UIStatusBarAnimationSlide];
    
    UIImage * image = [UIImage imageNamed: @"cut2.png"];
    
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef context = CGBitmapContextCreate(nil, 320, 480, 8, 4 * 320, colorSpace, kCGImageAlphaPremultipliedFirst);

    CGRect rect = CGRectMake(0, 0, 320, 480);
    CGColorRef fillColor = [[UIColor redColor] CGColor];
    CGContextSetFillColor(context, CGColorGetComponents(fillColor));
    //CGContextSetAlpha(context, 0.3);

    CGContextMoveToPoint(context, 7, 7);
    CGContextAddLineToPoint(context, 313, 7);
    CGContextAddLineToPoint(context, 313, 197);
    CGContextAddLineToPoint(context, 7, 197);

    CGContextClosePath(context);
    CGContextClip(context);
    CGContextDrawImage(context, rect, image.CGImage);
    CGImageRef imageMasked = CGBitmapContextCreateImage(context);
    CGContextRelease(context);
    UIImage *newImage = [UIImage imageWithCGImage:imageMasked];
    CGImageRelease(imageMasked);

    UIImageView *backView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    [self.view addSubview:backView];
    backView.image = newImage;
    backView.alpha = 0.5;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
